package org.example.springbootwebdemo.controller;


import org.example.springbootwebdemo.pojo.Address;
import org.example.springbootwebdemo.pojo.User;
import org.example.springbootwebdemo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.List;

@RestController
public class UserController {
    @Qualifier("userServiceImpl2")
    @Autowired
    private UserService userService;
    //????@Controller在哪里使用?为什么都没有用到?
//????为什么userController不需要接口?(其他接口的意义是什么? )
    @RequestMapping("/list")
    public List<User> list() {
        //调用userService的方法来进行逻辑处理,并返回一个List<User>的结果
        List<User> userList = userService.findAll();
        //3.响应数据
        return userList;
    }

    @RequestMapping("/find")
    public User find() {
        User user = new User(1, "张三", "zhangsan", "123456", 18, LocalDateTime.now());
        Address address = new Address("四川", "成都");
        user.setAddress(address);
        return user;
    }
}
